package hengtiansoft.com.myapplication.ormlite;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.test.AndroidTestCase;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import hengtiansoft.com.myapplication.BaseActivity;

/**
 * Created by lu on 16/3/11.
 */
public class OrmListTest extends Activity {

    DatabaseHelper helper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        testAddUser();
        helper = DatabaseHelper.getHelper(getApplicationContext());
    }


    public void testAddUser() {
        User u1 = new User("lu1", "aaa");
        if (helper == null) {
            helper = DatabaseHelper.getHelper(getApplicationContext());
        }
        try {
            helper.getUserDao().create(u1);
            helper.getUserDao().create(u1);
            helper.getUserDao().create(u1);
            u1 = new User("lu2", "bbb");
            helper.getUserDao().create(u1);
            helper.getUserDao().create(u1);
            doit();
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }


    public void doit() {
//        ArrayAdapter<String> a = new ArrayAdapter<String>();


        User user = new User("my", "android");
        user.setId(2);
        try {
            List<User> list = helper.getUserDao().queryForAll();
            Log.e("lu", list.get(6).getMsg().toString());
            Log.e("lu", list.get(8).getMsg().toString());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onDestroy() {
        helper.close();
        super.onDestroy();
    }
}
